
/**
 * Write a description of class Employee here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
import java.util.*;
public class Employee
{
    private static int numSecu =100;
    private String nom;
    private int numeroSecu;
    private Contrat contrat = null;
    private List<Contrat> oldContrats = new ArrayList<Contrat>();
    
    public Employee ( String nom, Contrat contrat){
    	
    	this.nom = nom;
    	this.numeroSecu = numSecu;
    	numSecu++;
    	this.contrat=contrat;
    	contrat.setEmployee(this);
    }
	
    public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		if(nom!=null)
			this.nom = nom;
	}
	public int getNumeroSecu() {
		return numeroSecu;
	}
	public void setNumeroSecu(int numeroSecu) {
		if(numeroSecu>0)
			this.numeroSecu = numeroSecu;
	}
	public Contrat getContrat() {
		return contrat;
	}
	public void setContrat(Contrat contrat) {
		if(!(this.contrat!=null)){
			removeContrat();
			this.contrat = contrat;
		}
			
	}
	public List<Contrat> getOldContrats() {
		return oldContrats;
	}
	private void setOldContrats(List<Contrat> oldContrats) {
		this.oldContrats = oldContrats;
	}
	
	public void removeContrat(){
		if(contrat.getType().equals(contrat.getTypeContratcdi())){
			contrat.setFin(contrat.getDebut()+10);
		}
		oldContrats.add(contrat);
		contrat=null;
		
	}
	
	public void ajouterAncienContrat(Contrat c){
		if (c.getFin()!=0)
			oldContrats.add(c);
			
	}
	
	public int calculAncienSalaireTotal(){
		
		int somme=0;
		
		Iterator it = oldContrats.iterator();
		while(it.hasNext()){
			Contrat c = (Contrat)it.next();
			somme += (c.getFin()-c.getDebut())*c.getSalaire();
		}
		return somme;
		
	}
	
	public int nbrAncienContratChezEntreprise(String nom){
		
		int somme=0;
		
		Iterator it = oldContrats.iterator();
		while(it.hasNext()){
			Contrat c = (Contrat)it.next();
			if(c.getNomEntreprise().equals("nom"))
				somme++;
		}
		return somme;
		
	}
    
  
}
